const fs = window.require("fs").promises;
// const path = require("path");

export const readFile = (path) => fs.readFile(path, "utf-8");
export const writeFile = (path, content) => fs.writeFile(path, content, "utf-8");
export const renameFile = (path, newPath) => fs.rename(path, newPath);
export const delFile = (path) => fs.unlink(path);


export const mapArr = (arr) => arr.reduce((map, item) => ({
  ...map,
  [item.id]: item
}), {});

export const getParentNode = (node, parentClassName) => {
  let currentEle = node;
  while (currentEle !== null) {
    if (currentEle.classList.contains(parentClassName)) {
      return currentEle;
    }
    currentEle = currentEle.parentNode;
  }
  return false;
};

// 测试
// const testPath = path.join(__dirname, "test.js");
// readFile(testPath).then(data => {
//   console.log(data);
// });